package com.ccrc.websocket;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Scanner;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_17;
import org.java_websocket.handshake.ServerHandshake;

public class WebsocketClient {

	public static void main(String[] args) throws URISyntaxException {

		String url = "ws://127.0.0.1:8080/wsTest/websocketServer";
		WebSocketClient wc = new WebSocketClient(new URI(url), new Draft_17()) {

			@Override
			public void onOpen(ServerHandshake handshakedata) {
				System.out.println(handshakedata.getHttpStatusMessage());
			}

			@Override
			public void onMessage(String message) {
				System.out.println(message);
			}

			@Override
			public void onError(Exception ex) {
				ex.printStackTrace();
			}

			@Override
			public void onClose(int code, String reason, boolean remote) {
			}
		};

		wc.connect();
		int index = 0;
		while (true) {
			Scanner scanner = new Scanner(System.in);
			String message = scanner.nextLine();
			if (message.equals("q")) {
				wc.close();
				break;
			}
			/*scanner.close();*/
			if(index == 0){				
				wc.send("shuchudianyaUbc");
			} else {
				
			}
			
			
		}
	}
}
